package com.jh.controller;

import com.jh.dto.StoreCashierProductPageQueryDTO;
import com.jh.result.PageResult;
import com.jh.result.ListResult;
import com.jh.result.Result;
import com.jh.service.StoreCashierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/storeCashier")
@Slf4j
@Api(tags = "工作台相关接口")
public class StoreCashierController {
    @Autowired
    private StoreCashierService storeCashierService;

    @GetMapping("/getStoreCashierInventoryList")
    @ApiOperation("工作台库存分页查询")
    public Result<PageResult> page(StoreCashierProductPageQueryDTO storeCashierProductPageQueryDTO){
        log.info("工作台库存分页查询,storeCashierProductPageQueryDTO：{}",storeCashierProductPageQueryDTO);
        try {
            PageResult pageResult = storeCashierService.page(storeCashierProductPageQueryDTO);
            return Result.success(pageResult);
        } catch (Exception e) {
            log.error("工作台库存分页查询失败", e);
            return Result.error("该商品不存在或已售罄");
        }
    }

    @GetMapping("/getPIdAndColorData")
    @ApiOperation("工作台根据pId查询颜色和对应的id")
    public Result<ListResult> getPIdAndColorData(@RequestParam(name = "productCode", required = true) String productCode){
        log.info("工作台根据pId查询颜色和对应的id,productCode：{}",productCode);
        ListResult pageResult2 =storeCashierService.getPIdAndColorData(productCode);
        return Result.success(pageResult2);
    }

    @GetMapping("/getPdIdAndSizeTypeData")
    @ApiOperation("工作台根据pId查询颜色和对应的id")
    public Result<ListResult> getPdIdAndSizeTypeData(@RequestParam(name = "id", required = true) Long id){
        log.info("工作台根据pId查询颜色和对应的id,id：{}",id);
        ListResult pageResult2 =storeCashierService.getPdIdAndSizeTypeData(id);
        return Result.success(pageResult2);
    }


}
